package com.breadenglish.cms.api.app.gateway.manager;


import com.breadenglish.cms.api.app.common.page.QueryPage;
import com.breadenglish.cms.api.app.gateway.anotation.AppPaging;
import com.breadenglish.cms.api.app.gateway.model.WhoBeLike;
import com.breadenglish.cms.api.app.gateway.service.WhoBeLikeService;
import com.breadenglish.cms.api.app.gateway.util.Util;
import org.jsondoc.core.annotation.*;
import org.jsondoc.core.pojo.ApiStage;
import org.jsondoc.core.pojo.ApiVisibility;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;

@Api(name = "who BE like", description = "who BE like 资源服务", group = "客户端接口", visibility = ApiVisibility.PUBLIC, stage = ApiStage.RC)
@ApiVersion(since = "1.0", until = "2.12")
@ApiAuthNone
@RestController
@RequestMapping(value = "/whobelikes")
public class WhoBeLikeController {

    public static final String file_url = "http://video.breadenglish.com/who_be_like/";

    LinkedHashMap<Integer, WhoBeLike> data = new LinkedHashMap();

    @Resource
    private WhoBeLikeService whoBeLikeService;

    public WhoBeLikeController() {
        int id = 100;
        data.put(id, WhoBeLike.buildDetails(id--, "开心的不要不要的", "就这个feel倍儿爽！", Util.parseToDate("2015-02-17"), file_url + "07.jpg", file_url + "7_GaGa_happy_mixdown.mp3", "fullSizeImage", "nextTitle", "backgoundMusic", "no", true));
        data.put(id, WhoBeLike.buildDetails(id--, "So Fine!", "各种你不知道的Fine", Util.parseToDate("2015-03-16"), file_url + "08.jpg", file_url + "8_GaGa_Fine_mixdown.mp3", "fullSizeImage", "nextTitle", "backgoundMusic", "no", true));
        data.put(id, WhoBeLike.buildDetails(id--, "Oral English?", "把Oral留给伴侣，把 English 留给自己", Util.parseToDate("2015-04-17"), file_url + "09.jpg", file_url + "9_GaGa_Oral_English_mixdown.mp3", "fullSizeImage", "nextTitle", "backgoundMusic", "no", true));
        data.put(id, WhoBeLike.buildDetails(id--, "GaGa教你怎么going down Part I", "We are going dowwwwnnnnnnnnn!!!!!", Util.parseToDate("2015-05-17"), file_url + "10.jpg", file_url + "10_GaGa_going_Down_mixdown.mp3", "fullSizeImage", "nextTitle", "backgoundMusic", "no", true));
        data.put(id, WhoBeLike.buildDetails(id--, "胡歌到底说了什么？", "Gratitude/Mentor 现在再回去听听看胡歌的演讲吧！", Util.parseToDate("2015-06-17"), file_url + "11.jpg", file_url + "11_GaGa_mixdown.mp3", "fullSizeImage", "nextTitle", "backgoundMusic", "no", true));
        data.put(id, WhoBeLike.buildDetails(id--, "怎么“够淫荡”？", "让我们一起“荡”一下!!!", Util.parseToDate("2015-07-17"), file_url + "12.jpg", file_url + "12_GaGa_going_down_part_mixdown.mp3", "fullSizeImage", "nextTitle", "backgoundMusic", "no", true));
        data.put(id, WhoBeLike.buildDetails(id--, "单身狗 剁剁手！双十一特别节目！", "Single dog, Single dog Single all the day See AV, hit the plane, they are doing all the day, HEY!", Util.parseToDate("2015-08-17"), file_url + "13.jpg", file_url + "13_GaGa_mixdown.mp3", "fullSizeImage", "nextTitle", "backgoundMusic", "no", true));
        data.put(id, WhoBeLike.buildDetails(id--, "歪果仁的三字经！", "这样说，你就完美了！", Util.parseToDate("2015-09-17"), file_url + "14.jpg", file_url + "14_GaGa_mixdown.mp3", "fullSizeImage", "nextTitle", "backgoundMusic", "no", true));
        data.put(id, WhoBeLike.buildDetails(id--, "维蜜，她背后的秘密", "维蜜最神奇营销模式，模特最变态减肥方法！", Util.parseToDate("2015-10-17"), file_url + "15.jpg", file_url + "15_GaGa_weimi.mp3", "fullSizeImage", "nextTitle", "backgoundMusic", "no", true));
        data.put(id, WhoBeLike.buildDetails(id--, "教你如何读大牌", "Pray for Paris", Util.parseToDate("2015-11-17"), file_url + "16.jpg", file_url + "16_GaGa_dapai.mp3", "fullSizeImage", "nextTitle", "backgoundMusic", "no", true));
        data.put(id, WhoBeLike.buildDetails(id--, "BIG BANG", "Bang，是一个神奇又百变的词儿！", Util.parseToDate("2015-12-06"), file_url + "17.jpg", file_url + "17_GaGa_BANG_mixdown.mp3", "fullSizeImage", "nextTitle", "backgoundMusic", "no", true));

    }

    /*@ApiMethod
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public
    @ApiResponseObject
    WhoBeLike getById(@ApiPathParam(description = "根据ID获取whobelike数据") @PathVariable(value = "id") int id) {
        return data.get(id);
    }*/

    /*@ApiMethod
    @RequestMapping(method = RequestMethod.GET)
    public
    @ApiResponseObject
    Collection<WhoBeLike> get(@ApiQueryParam(name = "page", required = false, description = "页号")
                              @RequestParam(required = false, defaultValue = "1") int page,
                              @ApiQueryParam(name = "pageSize", required = false, description = "每页Size")
                              @RequestParam(required = false, defaultValue = "10") int pageSize) {


        int size = 10;
        int p = page - 1;
        return data.values().stream()
                .skip(p * size)
                .limit(size)
                .collect(Collectors.toList());
    }*/


    @ApiMethod
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ApiResponseObject
    public WhoBeLike getById(@ApiPathParam(description = "根据ID获取whobelike数据") @PathVariable(value = "id") int id) throws Throwable {
        return whoBeLikeService.queryWhoBeLikeById(Long.valueOf(id));
    }

    @ApiMethod
    @RequestMapping(method = RequestMethod.GET)
    @ApiResponseObject
    @AppPaging
    public List<WhoBeLike> get(@ApiQueryParam(name = "page", required = false, description = "页号")
                               @RequestParam(required = false, defaultValue = "1") int page,
                               @ApiQueryParam(name = "pageSize", required = false, description = "每页Size")
                               @RequestParam(required = false, defaultValue = "10") int pageSize) throws Throwable {
        List<WhoBeLike> result = whoBeLikeService.queryWhoBeLike();
        return result;
    }

}